home *** CD-ROM | disk | FTP | other *** search
/ CD Actual Thematic 7: Programming / CDAT7.iso / demos / VisualAge for Java 2.0 Entry / setup / data1.cab / ide-e / IDE / cache / LYNO2T (.txt) < prev    next >
Encoding:
Java Class File  |  1998-09-16  |  4.5 KB  |  177 lines

  1. package com.sun.java.swing;
  2.  
  3. import com.sun.java.swing.event.EventListenerList;
  4. import java.awt.event.ActionEvent;
  5. import java.awt.event.ActionListener;
  6. import java.io.Serializable;
  7.  
  8. public class Timer implements Serializable {
  9.    int initialDelay;
  10.    int delay;
  11.    boolean repeats = true;
  12.    boolean coalesce = true;
  13.    protected EventListenerList listenerList = new EventListenerList();
  14.    boolean eventQueued = false;
  15.    private static boolean logTimers;
  16.    Runnable doPostEvent = null;
  17.    long expirationTime;
  18.    Timer nextTimer;
  19.    boolean running;
  20.    static Class class$java$awt$event$ActionListener;
  21.  
  22.    public Timer(int delay, ActionListener listener) {
  23.       this.delay = delay;
  24.       this.initialDelay = delay;
  25.       this.doPostEvent = new DoPostEvent(this);
  26.       this.addActionListener(listener);
  27.    }
  28.  
  29.    public void addActionListener(ActionListener listener) {
  30.       EventListenerList var10000 = this.listenerList;
  31.       Class var10001 = class$java$awt$event$ActionListener;
  32.       if (var10001 == null) {
  33.          try {
  34.             var10001 = Class.forName("java.awt.event.ActionListener");
  35.          } catch (ClassNotFoundException var2) {
  36.             throw new NoClassDefFoundError(((Throwable)var2).getMessage());
  37.          }
  38.  
  39.          class$java$awt$event$ActionListener = var10001;
  40.       }
  41.  
  42.       var10000.add(var10001, listener);
  43.    }
  44.  
  45.    synchronized void cancelEvent() {
  46.       this.eventQueued = false;
  47.    }
  48.  
  49.    protected void fireActionPerformed(ActionEvent e) {
  50.       Object[] listeners = this.listenerList.getListenerList();
  51.  
  52.       for(int i = listeners.length - 2; i >= 0; i -= 2) {
  53.          Object var10000 = listeners[i];
  54.          Class var10001 = class$java$awt$event$ActionListener;
  55.          if (var10001 == null) {
  56.             try {
  57.                var10001 = Class.forName("java.awt.event.ActionListener");
  58.             } catch (ClassNotFoundException var4) {
  59.                throw new NoClassDefFoundError(((Throwable)var4).getMessage());
  60.             }
  61.  
  62.             class$java$awt$event$ActionListener = var10001;
  63.          }
  64.  
  65.          if (var10000 == var10001) {
  66.             ((ActionListener)listeners[i + 1]).actionPerformed(e);
  67.          }
  68.       }
  69.  
  70.    }
  71.  
  72.    public int getDelay() {
  73.       return this.delay;
  74.    }
  75.  
  76.    public int getInitialDelay() {
  77.       return this.initialDelay;
  78.    }
  79.  
  80.    public static boolean getLogTimers() {
  81.       return logTimers;
  82.    }
  83.  
  84.    public boolean isCoalesce() {
  85.       return this.coalesce;
  86.    }
  87.  
  88.    public boolean isRepeats() {
  89.       return this.repeats;
  90.    }
  91.  
  92.    public boolean isRunning() {
  93.       return this.timerQueue().containsTimer(this);
  94.    }
  95.  
  96.    synchronized void post() {
  97.       if (!this.eventQueued) {
  98.          this.eventQueued = true;
  99.          SwingUtilities.invokeLater(this.doPostEvent);
  100.       }
  101.  
  102.    }
  103.  
  104.    public void removeActionListener(ActionListener listener) {
  105.       EventListenerList var10000 = this.listenerList;
  106.       Class var10001 = class$java$awt$event$ActionListener;
  107.       if (var10001 == null) {
  108.          try {
  109.             var10001 = Class.forName("java.awt.event.ActionListener");
  110.          } catch (ClassNotFoundException var2) {
  111.             throw new NoClassDefFoundError(((Throwable)var2).getMessage());
  112.          }
  113.  
  114.          class$java$awt$event$ActionListener = var10001;
  115.       }
  116.  
  117.       var10000.remove(var10001, listener);
  118.    }
  119.  
  120.    public void restart() {
  121.       this.stop();
  122.       this.start();
  123.    }
  124.  
  125.    public void setCoalesce(boolean flag) {
  126.       this.coalesce = flag;
  127.    }
  128.  
  129.    public void setDelay(int delay) {
  130.       if (delay < 0) {
  131.          throw new RuntimeException("Invalid initial delay: " + delay);
  132.       } else {
  133.          this.delay = delay;
  134.          if (this.isRunning()) {
  135.             TimerQueue queue = this.timerQueue();
  136.             queue.removeTimer(this);
  137.             this.cancelEvent();
  138.             queue.addTimer(this, System.currentTimeMillis() + (long)delay);
  139.          }
  140.  
  141.       }
  142.    }
  143.  
  144.    public void setInitialDelay(int initialDelay) {
  145.       if (initialDelay < 0) {
  146.          throw new RuntimeException("Invalid initial delay: " + initialDelay);
  147.       } else {
  148.          this.initialDelay = initialDelay;
  149.       }
  150.    }
  151.  
  152.    public static void setLogTimers(boolean flag) {
  153.       logTimers = flag;
  154.    }
  155.  
  156.    public void setRepeats(boolean flag) {
  157.       this.repeats = flag;
  158.    }
  159.  
  160.    public void start() {
  161.       this.timerQueue().addTimer(this, System.currentTimeMillis() + (long)this.getInitialDelay());
  162.    }
  163.  
  164.    public void stop() {
  165.       this.timerQueue().removeTimer(this);
  166.       this.cancelEvent();
  167.    }
  168.  
  169.    TimerQueue timerQueue() {
  170.       return TimerQueue.sharedInstance();
  171.    }
  172.  
  173.    static boolean access$logTimers() {
  174.       return logTimers;
  175.    }
  176. }
  177.